﻿<?php
require("header.php");
require("left.php");
?>
<?php
require("admin/conn.php");
if(isset($_GET['page']))     //由GET方法获得页面传入当前页数的参数
{
    $page = $_GET['page'];
}
else
{
    $page = 1;
}
$page_size = 5;              //每页显示5条数据

//获取数据总量
$sql = 'select * from blogr ';
$result = mysql_query($sql);
$total = mysql_num_rows($result);

//开始计算总页数
if($total)
{
    //如果总数据量小于$page_size，那么只有一页
    if($total < $page_size)
        $page_count = 1;
    //如果有余数，则总页数等于总记录数除以页数的结果取整再加1
    if($total % $page_size)
    {
        $page_count = (int)($total/$page_size) + 1;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果
    else
    {
        $page_count = $total/$page_size;
    }
}
else
{
    $page_count = 0;
}
//翻页链接

$turn_page = '';
if($page == 1)
{
    $turn_page .= '首页 | 上一页 |';
}
else
{
    $turn_page .= '<a href=blogr.php?page=1> 首页</a> | <a href=blogr.php?page='.($page-1).'> 上一页 </a> |';
}
if($page == $page_count || $page_count == 0)
{
    $turn_page .= ' 下一页 | 尾页';
}
else
{
    $turn_page .= '<a href=blogr.php?page='.($page+1).'> 下一页 </a>|<a href=blogr.php?page='.$page_count.'> 尾页 </a>';
}

$sql = 'SELECT * FROM blogr ORDER BY br_Data DESC limit '. ($page-1)*$page_size .', '.$page_size;
$result = mysql_query($sql) OR die("<br/>ERROR: <b>".mysql_error()."</b><br/>产生问题的SQL：".$sql);
?>
        <div id="main">
		    <h4>留言板</h4>
		        <div class="leave">
<?php
if($num = mysql_num_rows($result))
{
    while($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
?>
		             <p class="content">昵称：<?php echo $row['br_name']; ?></p>
					 <p class="time"><?php echo $row['br_Data']; ?></p>
					 <p class="content"><?php echo $row['br_content']; ?></p>	
					 <p class="content">Email:&nbsp;&nbsp;&nbsp;<?php echo $row['br_email']; ?></p>
<?php
}}
?>
                </div>
		       <div id="write">
				<form name="r" action="admin/addblogr.php" method="post">
					<p>名&nbsp;&nbsp;&nbsp;字：&nbsp;&nbsp;<input name="br_name" type="text" /></p>
					<p>E-mail：&nbsp;&nbsp;</th><input name="br_email" type="text" /></p>
					<p>
			        <textarea name="br_content" id="br_content" rows="50" cols="152" style="width: 480px; height: 200px">在这里写留言</textarea> 
					<input name="留言" type="submit" id="留言" value="留言" />
				    </p>
			    </form>
		      </div>
              			    <script charset="utf-8" src="editor/kindeditor-min.js"></script>
					<script>
						KE.show({
							id : 'br_content',
							urlType : 'absolute',
							width: '560px',
							resizeMode:0,
							allowUpload : false,
							filterMode : true,
										items : [
							'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
							'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
							'insertunorderedlist', '|', 'emoticons', 'image', 'link']
						});
				</script>
		</div>	
<?php
require("footer.php");
?>